package smartbooks.ui.helper;

import smartbooks.exceptions.MyException;
import smartbooks.ui.util.CommonConstants;
import smartbooksdb.valuebean.Credentials;

/**
 *
 * @author Ankit
 */
public class LoginHelper implements CommonConstants {
    /**
     * This method is used to validate the login panel
     * @param credentials
     * @return 'true' if login panel is validated or else 'false'
     * @throws MyException
     */
    public static boolean validateLogin(Credentials credentials) throws MyException {
        boolean loginPanelValidated = true;
        
        if(null==credentials.getUsername() || credentials.getUsername().length()==0) {
            throw new MyException(USERNAME, "Username cannot be blank");
        }
        
        if(null==credentials.getPassword() || credentials.getPassword().length()==0) {
            throw new MyException(PASSWORD, "Password cannot be blank");
        }
        
        return loginPanelValidated;
    }
}
